package com.hnjk.cbts;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ErrorMessageHandler extends AbstractHandler {
	private static final Logger  logger = LoggerFactory.getLogger(ErrorMessageHandler.class);

	private String message = "";

	public void setMessage(String message) {
		this.message = message;
	}	

	@Override
	public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		if ("".equals(message)) {
			// do nothing
		} else {
			logger.info("错误访问");
			response.setContentType("text/plain; charset=utf-8");
			response.setStatus(HttpServletResponse.SC_OK);
			PrintWriter writer = response.getWriter();
			writer.println(message);
			baseRequest.setHandled(true);
		}
	}

}
